package com.cyh.pangu.offer;

/**
 * @author cuiyh9
 * @date 2020/8/27
 */
public class Offer05 {
    public String replaceSpace(String s) {
        if (s == null || s.length() == 0) {
            return s;
        }
        char[] result = new char[s.length() * 3];
        char[] sCharArr = s.toCharArray();
        int j = 0;
        for (char cc : sCharArr) {
            if (cc == ' ') {
                result[j++] = '%';
                result[j++] = '2';
                result[j++] = '0';
            } else {
                result[j++] = cc;
            }
        }
        return new String(result, 0, j);
    }




    public static void main(String[] args) {
        Offer05 offer05 = new Offer05();
        String result = offer05.replaceSpace("We are happy");
        System.out.println("result:" + result);
    }

}
